package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Map;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TourismNews;
import com.ruoyi.system.service.ITourismNewsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 景区动态Controller
 *
 * @author gqd
 * @date 2020-12-29
 */
@RestController
@RequestMapping("/system/news")
public class TourismNewsController extends BaseController
{
    @Autowired
    private ITourismNewsService tourismNewsService;

    /**
     * 查询景区动态列表
     */
    @PreAuthorize("@ss.hasPermi('system:news:list')")
    @GetMapping("/list")
    public TableDataInfo list(TourismNews tourismNews)
    {
        startPage();
        List<TourismNews> list = tourismNewsService.selectTourismNewsList(tourismNews);
        return getDataTable(list);
    }

    /**
     * 导出景区动态列表
     */
    @PreAuthorize("@ss.hasPermi('system:news:export')")
    @Log(title = "景区动态", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TourismNews tourismNews)
    {
        List<TourismNews> list = tourismNewsService.selectTourismNewsList(tourismNews);
        ExcelUtil<TourismNews> util = new ExcelUtil<TourismNews>(TourismNews.class);
        return util.exportExcel(list, "news");
    }

    /**
     * 获取景区动态详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:news:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tourismNewsService.selectTourismNewsById(id));
    }

    /**
     * 新增景区动态
     */
    @PreAuthorize("@ss.hasPermi('system:news:add')")
    @Log(title = "景区动态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TourismNews tourismNews)
    {
        return toAjax(tourismNewsService.insertTourismNews(tourismNews));
    }

    /**
     * 修改景区动态
     */
    @PreAuthorize("@ss.hasPermi('system:news:edit')")
    @Log(title = "景区动态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TourismNews tourismNews)
    {
        return toAjax(tourismNewsService.updateTourismNews(tourismNews));
    }

    /**
     * 删除景区动态
     */
    @PreAuthorize("@ss.hasPermi('system:news:remove')")
    @Log(title = "景区动态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tourismNewsService.deleteTourismNewsByIds(ids));
    }

    /**
     * 查询景区动态信息
     * @return
     */
    @PostMapping("/selectNews")
    public AjaxResult selectNews(){
        return tourismNewsService.selectNews();
    }

    @PostMapping("/selectNewsById")
    public AjaxResult selectNewsById(@RequestBody Map map){
        Integer newsId = (Integer) map.get("newsId");
        return tourismNewsService.selectNewsById(newsId);
    }
}
